#include "precompile.h"

#include "PagePresentation.h"

PagePresentation::PagePresentation()
{
}

PagePresentation::~PagePresentation()
{

}

void PagePresentation::Present(Graphics* graphics,PresentationContext& context)
{
	sys::InterfacePtr<IPage> pIFPage(context.GetTarget());

	Size pagesize(graphics->UnitMMtoLine(pIFPage->getPageWidth()),
							graphics->UnitMMtoLine(pIFPage->getPageHeight()));
	Rect pageRect(0.0f,0.0f,pagesize.cx,pagesize.cy);

	//draw outer page rect
	graphics->DrawRectangle(Pen(Color::Black),pageRect);

	//draw inner page rect
	Rect innerPageRect = pageRect;
	Rect deflectInnerRect(graphics->UnitMMtoLine(10.0f),
								 graphics->UnitMMtoLine(10.0f),
								 graphics->UnitMMtoLine(10.0f),
								 graphics->UnitMMtoLine(10.0f));
	innerPageRect.Deflect(deflectInnerRect);
	graphics->DrawRectangle(Pen(Color::Red,3.0f),innerPageRect);

	//draw inner page rect
	real leftMargin = graphics->UnitMMtoLine(pIFPage->getPageLeftMargin()); 
	real topMargin = graphics->UnitMMtoLine(pIFPage->getPageTopMargin()); 
	real rightMargin = graphics->UnitMMtoLine(pIFPage->getPageRightMargin()); 
	real bottomMargin = graphics->UnitMMtoLine(pIFPage->getPageBottomMargin()); 
	Rect marginRect(leftMargin,topMargin,rightMargin,bottomMargin);
	pageRect.Deflect(marginRect);

	//draw tag
	Pen pen(Color::LightGray);
	Point ptVertLineLeftTop(pageRect.left,pageRect.top-topMargin/4.0f);
	Point ptHorLineLeftTop(pageRect.left-leftMargin/4.0f,pageRect.top);
	Point ptVertLineRightTop(pageRect.right,pageRect.top-topMargin/4.0f);
	Point ptHorLineRightTop(pageRect.right+leftMargin/4.0f,pageRect.top);

	graphics->DrawLine(pen,ptVertLineLeftTop,pageRect.LeftTop());
	graphics->DrawLine(pen,ptHorLineLeftTop,pageRect.LeftTop());
	graphics->DrawLine(pen,ptVertLineRightTop,pageRect.RightTop());
	graphics->DrawLine(pen,ptHorLineRightTop,pageRect.RightTop());
}